package export.monster
{
    import base.BaseBullet;
    
    import com.dusk.util.FilterUtil;
    
    import com.dusk.util.RandomUtil;
    
    import com.game.data.constant.FrameRate;
    
    import com.game.manager.AnimationManager;
    
    import base.BaseMonster;
    
    import export.bullet.EnemyMoveBullet;
    import export.bullet.FollowTargetBullet;
    import export.bullet.RegionBullet;
    
    import flash.geom.Rectangle;
    
    public class Monster104 extends BaseMonster
    {
        public function Monster104()
        {
            super();
        }
        
        override protected function initAttribute():void
        {
            super.initAttribute();
            mavo.attackRange = 300;
            mavo.normalAttackRate = 45;
        }
        
        override protected function initBBDC():void
        {
            bbdc = AnimationManager.getAnimation("Monster104Action");
            bbdc.setAction("idle");
            bbdc.turnRight();
            bbdc.addCallBack(onEnterFrame, onActionOver);
            bodyContainer.addChild(bbdc);
        }
        
        override protected function initCollideArea():void
        {
            collideBox = new Rectangle(-40, -110, 80, 110);
            super.initCollideArea();
        }
        
        override protected function onEnterFrame(action:String, frameCount:int):void
        {
            var b:BaseBullet;
            switch (action)
            {
                case "attack1":
                    if (frameCount == 3)
                    {
                        b = new RegionBullet();
                        with (b as RegionBullet)
                        {
                            setOwner(this);
                            setCollideArea(-20, -150, 210 * bbdc.getDirect(), 150);
                            setDestroyInCount(bbdc.frameLeft);
                            setOwner(this);
                            setHurt(getActionHurt(action));
                            setAction("Monster104Attack1");
                            setDirect(bbdc.getDirect());
                        }
                        b.setHurt(getActionHurt("attack1"));
                    }
                    break;
                case "skill1":
                    if (frameCount == 1)
                    {
                        b = new FollowTargetBullet("Monster104Skill1");
                        with (b as FollowTargetBullet)
                        {
                            setOwner(this);
                            setDestroyInCount(12);
                            setDisable();
                            setScale(2, 2);
                            setClipOffset(-16, -55);
                        }
                        FilterUtil.setGlow(b,0x6633CC,1,15,15);
                        FilterUtil.setBlur(b,3,3);
                        FilterUtil.clearCache();
                    }
                    if (frameCount == 13)
                    {
                        b = new EnemyMoveBullet("Monster104Skill1");
                        with (b as EnemyMoveBullet)
                        {
                            setOwner(this);
                            setAction("Monster104Skill1");
                            setSpeed(bbdc.getDirect() * 50, 0);
                            setSpeedAdd(-2 * bbdc.getDirect(), 0);
                            setDistance(5000);
                            setScale(2, 2);
                            setClipOffset(0, -55);
                        }
                        b.setHurt(getActionHurt("skill1"));
                        FilterUtil.setGlow(b,0x6633CC,1,15,15);
                        FilterUtil.setBlur(b,3,3);
                        FilterUtil.clearCache();
                    }
                    break;
                case "skill2":
                    if (frameCount == 12)
                    {
                        b = new FollowTargetBullet("Monster104Skill2");
                        with (b as FollowTargetBullet)
                        {
                            setOwner(this);
                            setAction("Monster104Skill2");
                            setDestroyInCount(FrameRate.ANIMATE_FRAME_RATE * 5);
                            setClipOffset(-260.5, -471.45);
                            setScale(0.8, 0.8);
                            for (var i:int = FrameRate.ANIMATE_FRAME_RATE; i < 150; i += FrameRate.ANIMATE_FRAME_RATE)
                            {
                                b.setFuncWhenInCount(generateRandomWind, i);
                            }
                        }
                        b.setHurt(getActionHurt("skill2"));
                    }
            }
            if (b)
            {
                gc.gameScene.addChild(b);
                magicBulletArray.push(b);
            }
        }
        
        override protected function beforeSkill1Start():Boolean
        {
            return this.hasTarget() && AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget) < 400;
        }
        
        override protected function beforeSkill2Start():Boolean
        {
            return this.hasTarget() && AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget) < 200;
        }
        
        private function generateRandomWind(b:BaseBullet):void
        {
            var wind:EnemyMoveBullet = new EnemyMoveBullet("Monster104Wind");
            wind.setOwner(this);
            wind.setHurt(getActionHurt("skill2"));
            wind.setAction("Monster104Skill2");
            wind.flipClip();
            var direct:int = RandomUtil.randBoolean(bbdc.getDirect() == 1 ? 80 : 30) ? 1 : -1;
            wind.setSpeed(50 * direct, 0);
            wind.setDirect(direct);
            gc.gameScene.addChild(wind);
            magicBulletArray.push(wind);
        }
        
        override public function getActionHurt(action:String):int
        {
            var ratio:Number = 1;
            if (action == "skill1")
            {
                ratio = 1.6;
            }
            return super.getActionHurt(action) * ratio;
        }
    }
}